var express = require('express');
var router = express.Router();
var db = require("../tools/db")

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});
router.get("/api/banners",async function(req,res,next){
  let sqlBannel = "select * from e_banners"
  let bannels = await db(sqlBannel)
  let bannels2 = bannels[1].map(function(value){  //这里的value是数组项  是对象
    return{
      ...value,  //这里的value 
      image_src:"http://localhost:3000/uploads/"+value.image_src
    }
  
})
 let result = {status:200,msg:"ok",result:bannels2}
 res.send(result)
})

router.get("/api/synlessons",async function(req,res,next){
  let sqlBannel = "select * from e_course"
  let bannels = await db(sqlBannel)
  let bannels2 = bannels[1].map(function(value){  //这里的value是数组项  是对象
    return{
      ...value,  //这里的value 
      image_src:"http://localhost:3000/uploads/synlessons/"+value.image_src
    }
  
})
 let result = {status:200,msg:"ok",result:bannels2}
 res.send(result)
})


module.exports = router;
